/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import java.awt.Frame;
import java.util.Locale;
import java.util.ResourceBundle;
import javax.swing.SwingUtilities;

/**
 *
 * @author Johnny
 */
public class CustomerManagerPanel extends javax.swing.JPanel {
    private final ResourceBundle labels;
    
    private CustomersTableModel tableModel;
    private java.awt.Frame parent;
    /**
     * Creates new form CustomerManagerPanel
     */
    public CustomerManagerPanel(Frame parent) { 
        Locale locale = Locale.getDefault();
        labels = ResourceBundle.getBundle("labels",locale);
        initComponents();
        this.parent = parent;
        tableModel = (CustomersTableModel)CustomersTable.getModel(); //carsTable is Jtable
    }

    public CustomersTableModel getTableModel() {
        return tableModel;
    }


    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        CustomersTable = new javax.swing.JTable();
        newCustomerButton = new javax.swing.JButton();

        setMinimumSize(new java.awt.Dimension(600, 400));

        CustomersTable.setModel(new CustomersTableModel(PrintEnum.FULL));
        jScrollPane1.setViewportView(CustomersTable);

        newCustomerButton.setText(labels.getString("newCustomer")
        );
        newCustomerButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newCustomerButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 576, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(newCustomerButton)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 310, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(newCustomerButton)
                .addGap(31, 31, 31))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void newCustomerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newCustomerButtonActionPerformed

        SwingUtilities.invokeLater(new Runnable() {
            public void run() {

                AddCustomerDialog newCustomer = new AddCustomerDialog(parent, true);

                // newCustomer.setCustomersTableModel(tableModel);
                newCustomer.setVisible(true);

            }
        });
    }//GEN-LAST:event_newCustomerButtonActionPerformed

    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable CustomersTable;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton newCustomerButton;
    // End of variables declaration//GEN-END:variables
}
